package com.dc.chat.app.service.mp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dc.chat.entity.dao.FriendMessage;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FriendMessageService extends ServiceImpl<FriendMessageService.FriendMessageMapper,FriendMessage> {
    public List<FriendMessage> getFriendMessage(Integer friendId, Integer id) {
        LambdaQueryWrapper<FriendMessage> wrapper = Wrappers.lambdaQuery(new FriendMessage());
        wrapper.and(i->{
            i.eq(FriendMessage::getFromUserId,friendId).eq(FriendMessage::getToUserId,id);
        }).or(i->{
            i.eq(FriendMessage::getFromUserId,id).eq(FriendMessage::getToUserId,friendId);
        });
        wrapper.orderByAsc(FriendMessage::getCreateTime);
        List<FriendMessage> messages = baseMapper.selectList(wrapper);
        return messages;
    }

    public interface FriendMessageMapper extends BaseMapper<FriendMessage>{

    }
}
